const readline = require('readline-sync');
//1.转换成字符串型 变量.toString()
let num = 10;
let str = num.toString();
console.log(typeof str);
//2.强制转换 String()
console.log(String(num));
// 3.利用 + 做字符串拼接转换
console.log(111 + '');


//转换成数值型
// 1.parseInt()  转换成整数
let age = '18';
console.log(parseInt(age));
console.log(parseInt(3.14));//3
console.log(parseInt('3.14'));//3
console.log(parseInt('31.4abc'));//31
console.log(parseInt('314abc'));//314
console.log(parseInt('abc314'));//NaN

//2.parseFloat() 转换成浮点数
console.log(parseFloat('3.14'));//3.14
console.log(parseFloat('3.a4'));//3
console.log(parseFloat('3.14abc'));//3.14
console.log(parseFloat('abc3.14'));//NaN
console.log(parseFloat('3.14.256a'));//3.14
console.log(parseFloat('3.1a4.256'));//3.1

//3.Number()
//这个方法做整体转换，只要有其他字符则返回NaN
let str2 = '123';
console.log(Number(str2));
console.log(Number(123.4));//123.4
console.log(Number('123.4'));//123.4
console.log(Number('123.4a'));//NaN
console.log(Number('abc123.4a'));//NaN

// 4.利用算数运算转换  * / - 注意没有+
console.log('2' * 5);//10
console.log('2' * '5');//10
console.log('10' / 5);//2
console.log('2' - 5);//-3
console.log('2' + 5);//25

//转换成布尔型
console.log(Boolean(0));//false
console.log(Boolean(' '));//true
console.log(Boolean('0'));//true
console.log(Boolean(null));//false
console.log(Boolean(undefined));//false
console.log(Boolean(NaN));//false


// 练习：1.苹果7元1斤，输入数量，算总价
// let price = 7;
// console.log('你要买几斤');
// let count = readline.question();
// console.log(`一共是${price * count},打八折${price * count * 0.8}元`);

// 2.
console.log('请输入两个数');

let num1 = parseInt(readline.question());
let num2 = readline.question() - 0;
console.log(`和是${num1 + num2} `);
